package com.santoker.user.service.service.common.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.santoker.baseservice.enums.IsDeleteEnum;
import com.santoker.user.service.dao.VersionMapper;
import com.santoker.user.service.model.Version;
import com.santoker.user.service.service.common.IVersionService;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 固件版本表 服务实现类
 * </p>
 *
 * @author jiangs
 */
@Service
public class VersionServiceImpl extends ServiceImpl<VersionMapper, Version> implements IVersionService {

    @Override
    public Version getOne(String firmwareType, Integer version) {
        LambdaQueryWrapper<Version> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Version::getIsDelete, IsDeleteEnum.TYPE_0.getValue())
                    .eq(Version::getFirmwareType, firmwareType)
                    .gt(Objects.nonNull(version), Version::getVersion, version)
                    .orderByDesc(Version::getVersion);
        return getOne(queryWrapper, false);
    }

}
